package org.sws.domain.behavior.strategy.context;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.sws.domain.behavior.event.SendRebateMessageEvent;
import org.sws.domain.behavior.strategy.RebateStrategy;

import java.util.Map;

/**
 * @Author sws
 * @Date 2025/4/1 16:39
 * @description: 返利行为上下文
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RebateContext {

    private final Map<String, RebateStrategy> rebateStrategyMap;

    public String executeRebate(String rebateType, SendRebateMessageEvent.RebateMessage rebateMessage) {
        RebateStrategy strategy = rebateStrategyMap.get(rebateType);
        if (strategy == null) {
            log.error("请配置或检查返利策略实现类，rebateType:{},rebateMessage:{} ",rebateType,rebateMessage);
            throw new IllegalArgumentException("请配置或检查返利策略实现类");
        }
        return strategy.handleRebate(rebateMessage);
    }
}
